package com.qf.xiaomi.web.servlet;

import com.alibaba.fastjson.JSON;
import com.qf.xiaomi.pojo.GoodsType;
import com.qf.xiaomi.service.GoodsTypeService;
import com.qf.xiaomi.service.impl.GoodsTypeServiceImpl;
import com.qf.xiaomi.web.base.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@WebServlet("/goodstypeservlet")
public class GoodsTypeServlet extends BaseServlet {

    GoodsTypeService service = new GoodsTypeServiceImpl();

    /**
     * 获取商品 一级分类 列表
     * @param req
     * @param resp
     */
    public void goodstypelist(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //查询一级商品分类列表
        List<GoodsType> goodsTypeList =  service.getGoodsTypeL1();
        //响应前端
        resp.setCharacterEncoding("utf-8");
        PrintWriter writer = resp.getWriter();
        //把列表数据转换为 json数据
        String json = JSON.toJSONString(goodsTypeList);
        writer.write(json);
    }

}
